var name_e;
var password_e;
var tips;
var error_msg;

$(function () {
  tips = $("#login_form #tips");
  $("#login_form form").validate({
    submitHandler: function (form) {
      var req = $.ajax({
        url: "/accounts/api/user_valid",
        data: {'username': $.trim($("#username").val()), 
          'password': $.trim($("#password").val())},  
        async: false,
        cache: false
      });
      if (req.status == 404) {
        var s = req.responseText;
        tips.text(s);
      } else {
        form.submit();      
      }
    }
  });
  $("#login_form #username").rules('add', 
    {
      required: true,
      messages: {
        required: gettext("required")
      }
    }
  );
  $("#login_form #password").rules('add',
    {
      required: true,
      messages: {
        required: gettext("required")
      }
    }
  );
  $("#login_form form").valid();
  var ret = append_notes($("#notes"), 10, Infinity, "/notes/api/notes");
  var notes_cnt = ret[0];
  var max_id = ret[1];
  $("#show_place #max_id").val(max_id);
  if (notes_cnt < 10) {
    $("#show_place input .load_more").attr("disabled", "disabled");
  }
  $("#show_place input.load_more").click(function() {
    var max_id = $("#show_place #max_id").val();
    var ret = append_notes($("#notes"), 10, max_id, "/notes/api/notes");
    var notes_cnt = ret[0];
    var max_id = ret[1];    
    $("#show_place #max_id").val(max_id);
    if (notes_cnt < 10) {
      $(this).attr('disabled', 'disabled');
    }
  });
});